﻿using NCalc2;

namespace DataImporter
{
    /// <summary>
    /// 动态运行时
    /// </summary>
    public class DyncmicRuntime
    {
        /// <summary>
        /// 计算
        /// </summary>
        /// <param name="expression">表达式</param>
        /// <returns>计算结果</returns>
        public static bool Compute(string expression)
        {
            if (expression.IsNullOrEmpty())
                return true;
            return (bool)new Expression(expression).Evaluate();
        }

        /// <summary>
        /// 计算
        /// </summary>
        /// <param name="expression">表达式</param>
        /// <param name="sex">性别</param>
        /// <returns>计算结果</returns>
        public static bool Compute(string expression, string sex)
        {
            expression = expression?.Replace("sex", sex);
            return Compute(expression);
        }
    }
}
